package team.unstudio.unknownrpg_base;

import java.io.File;

import org.bukkit.plugin.java.JavaPlugin;

import indi.defoliation.unknownrpg.api.RPGItemManager;
import indi.defoliation.unknownrpg.api.attribute.Attribute;
import indi.defoliation.unknownrpg.api.attribute.NumberAttribute;
import team.unstudio.unknownrpg_base.attribute.*;
import team.unstudio.unknownrpg_base.attribute.level.ItemLevelAttribute;
import team.unstudio.unknownrpg_base.attribute.quality.QualityManager;
import team.unstudio.unknownrpg_base.attribute.quality.YamlQualityFile;
import team.unstudio.unknownrpg_base.config.AttributeConfigManager;
import team.unstudio.unknownrpg_base.loretable.LoreTableManager;

public class UnknownRPGBase extends JavaPlugin
{
	private static UnknownRPGBase INSTANCE;
	
	public UnknownRPGBase() {
		INSTANCE = this;
	}
	public static void main(String[] args) {
		
		
	}
	public void onEnable() {
		
		File qualityFile = new File(this.getDataFolder()+"quality.yml");
		if(!qualityFile.exists())
			this.saveResource("quality.yml", true);
		QualityManager.setQualityFile(new YamlQualityFile(qualityFile));
		AttributeConfigManager.init();
		register();
		AttributeConfigManager.save();
	}
	
	private void register() {
		register(new Attribute[] {
				new BlockChanceAttribute(0),
				new CritAttribute(0),
				new CritChanceAttribute(0),
				new DamageAttribute(0),
				new DefenseAttribute(0),
				new LevelLimitAttribute(0),
				new ItemLevelAttribute(0),
				new LoreAttribute(),
		});
	}
	
	private void register(Attribute... attributes) {
		for(Attribute att : attributes) {
			RPGItemManager.registerAttribute(att);
			AttributeConfigManager.registeAttribute(att,att.serialize());
			LoreTableManager.putReplacer(att);
			if(att instanceof NumberAttribute<?>)
				LoreTableManager.putReplacer((NumberAttribute<?>)att);
		}
	}
	
	public static UnknownRPGBase getInstance() {
		return INSTANCE;
	}
	
}
